<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

  <script>
    function asyncFun(item) {
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          console.log('item:', item)
          resolve(item)
        }, 1000)
      })

    }
    function fun1() {
      let arr = [1, 2, 3]
      console.log('---start---')
      arr.forEach(async item => {
        await asyncFun(item)
      })
      console.log('---end---')
    }
    fun1()
    // 期望效果： start 1 2 3 end
    // 实际效果： start end 1 2 3
    async function fun2() {
      let arr = [1, 2, 3]
      console.log('---start---')
      for (let i = 0; i < arr.length; i++) {
        await asyncFun(arr[i])
      }
      console.log('---end---')
    }
    // fun2()

  </script>
</body>

</html>